const { defineConfig } = require('@vue/cli-service')

// The path to the CesiumJS source code
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const webpack = require('webpack');



module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    hot:true, // 它是热更新：只更新改变的组件或者模块，不会整体刷新页面
    open: false, // 是否自动打开浏览器
    allowedHosts:'all',
    // 代理示例
    proxy: {
      '/3dtiles':{
        target:'http://gis.bjcity.net',
        ws:true,
        changeOrigin:true
      },
      '/files':{
        target:'http://43.138.122.217:8080',
        ws:true,
        changeOrigin:true
      },
      '/sswyTiles':{
        target:'http://gd.cecc.cn',
        ws:true,
        changeOrigin:true
      },
      '/prod-api': {
        target: 'http://43.138.122.217:8080',
        ws: false,
        changeOrigin: true
      },
      '/model': {
        target: 'http://localhost:9003',
        ws: false,
        changeOrigin: true
      }
    }
  },
  configureWebpack: {
    output: {
      sourcePrefix: ''
    },
    resolve: {
      fallback: { "https": false, "zlib": false, "http": false, "url": false },
      mainFiles: ['index', 'Cesium']
    },
    plugins: [
      // Copy Cesium Assets, Widgets, and Workers to a static directory
      new CopyWebpackPlugin({
        patterns: [
          { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' },
          { from: path.join(cesiumSource, 'Assets'), to: 'Assets' },
          { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }
        ]
      }),
      new webpack.DefinePlugin({
        // Define relative base path in cesium for loading assets
        CESIUM_BASE_URL: JSON.stringify('')
      })
    ],
  },
})
